<?php

class Application_Form_RmaAdd extends Zend_Form
{

	public function init()
	{
		$sapCodeValidator = new Zend_Validate_Db_RecordExists(
				array(
						'table' => 'bis.tbl_mshData',
						'field' => 'sapCode',
						'exclude' => array(
								'field' => 'status',
								'value' => 'I'
						)
				)
		);
		
		$customermapper = new Application_Model_CustomerMapper();
		
		$this->setDecorators(array(
		
				array('ViewScript', array(
						// the view template script
						'viewScript' => 'forms/rmaadd.phtml'))
		));
		
		$this->setMethod('post');
		$this->setAction('add');
		
		$status = new Zend_Form_Element_Hidden('status');
		$status->setValue('entered');

		
		$partyNumber = new Zend_Form_Element_Select('partyNumber');
		$partyNumber->setLabel('Customer');
		$partyNumber->addMultiOption('', '');
		$partyNumber->addMultiOptions($customermapper->getCustomersForRma());
		$partyNumber->setRequired(true);
		
		$salesRepName = new Zend_Form_Element_Text('salesRepName');
		$salesRepName->setLabel('Salesrep');
		$salesRepName->setOptions(array('readonly' => 'readonly'));
		$salesRepName->setIgnore(true);
		
		$sapCode = new Zend_Form_Element_Text('sapCode');
		$sapCode->setLabel('MSH SAP Code');
		$sapCode->setOptions(array('size' => '5'));
		$sapCode->addValidator($sapCodeValidator);
		
		$outlet = new Zend_Form_Element_Text('outlet');
		$outlet->setLabel('MSH Outlet');
		$outlet->setOptions(array('readonly' => 'readonly', 'size' => '50'));
		$outlet->setIgnore(true);
		
		$reference = new Zend_Form_Element_Text('reference');
		$reference->setLabel('Reference number');
		$reference->setRequired(true);
		
		$date = new Zend_Form_Element_Text('createdOn');
		$date->setLabel('created on');
		$date->setRequired(true);
		$date->setOptions(array('readonly' => 'readonly'));
		$date->setValue(date('Y-m-d'));
		
		$createdBy = new Zend_Form_Element_Text('createdBy');
		$createdBy->setLabel('created by');
		$createdBy->setRequired(true);
		$createdBy->setOptions(array('readonly' => 'readonly'));
		$createdBy->setValue(Zend_Auth::getInstance()->getIdentity()->username);
		
		$rmaReason = new Zend_Form_Element_Select('rmaReason');
		$rmaReason->setLabel('RMA reason');
		$rmaReason->setRequired(true);
		$rmaReason->setMultiOptions(array('SBR' => 'stock balance return', 'DCR' => 'defective return', 'MIS' => 'misshipment', 'REF' => 'customer refusal'));
		
		$contactEmail = new Zend_Form_Element_Text('contactEmail');
		$contactEmail->setLabel('Customer email');
		$contactEmail->setRequired(true);
		$contactEmail->setOptions(array('size' => '50'));
				
		$submit = new Zend_Form_Element_Submit('submit');
		$submit->setLabel('Create request and continue adding items');
		
		$this->addElements(array($status, $partyNumber, $salesRepName, $rmaReason, $sapCode, $outlet, $reference, $date, $contactEmail, $createdBy, $submit));
		
		//Enable Zend form inputboxes and error output
		$this->setElementDecorators(array('ViewHelper', 'Errors'));

		
	}


}

